#pragma once
#include "Vertex.h"
#include "Texture.h"
#include "Normal.h"
#include "Triangle.h"
#include "GLTriangleBatch.h"
#include <fstream>
#include <vector>
#include <string>

class ObjectLoader {
private:
	const char* objFilePath;

	// these are pretty important
	std::vector<SpatialCoordinate> spatialCoordinates;
	std::vector<Texture> textures;
	std::vector<Normal> normals;
	std::vector<Triangle> allTriangles;

public:
	ObjectLoader(const char* path);
	void loadObject(GLTriangleBatch* objectBatch);
	void setPath(const char* filepath);
	void drawHalfOfSphere(GLTriangleBatch& sphereBatch, GLfloat fRadius, GLint iSlices, GLint iStacks);

private:
	void readSpatialCoordinates(std::vector<std::string> *words);
	void readTextureCoordinates(std::vector<std::string> *words);
	void readNormalCoordinates(std::vector<std::string> *words);
	void breakIntoWords(std::string& line, std::vector<std::string> *words);
	void prepareParameters(Triangle& aTriangle, M3DVector3f* vVertex, M3DVector2f* vTexture, M3DVector3f* vNormal);
	void printLineWords(std::vector<std::string> *words);
	void splitWord(std::vector<int> *indices, std::string& word);
	void readATriangle(std::vector<std::string> *words);
};
